package b4.scene.town.building
{
	import as3isolib.display.*;
	import as3isolib.geom.*;
	
	import b4.model.config.*;
	import b4.model.town.*;
	import b4.scene.town.*;
	import b4.net.*;
	import b4.util.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.utils.*;
	import flash.ui.Mouse;
	
	public class Building extends IsoSprite
	{
		public var buildingModel:BuildingModel;
		private var buildingSprite:IsoSprite;
		
		public function Building(buildingModel:BuildingModel)
		{
			super();
			this.buildingModel = buildingModel;
			//加载建筑图片
			var buildingConfig:Object = GameConfig.basicConfig.buildingConfigs[buildingModel.buildingIndex];
            var IsoImage:Class = ResourceManager.getInstance().getClassByName(buildingConfig.className);
            var isoImage:Sprite = new IsoImage();
            isoImage.cacheAsBitmap = true;
			setSize(Town.gridWidth, Town.gridWidth, Town.gridWidth);

			buildingSprite = new IsoSprite();
			buildingSprite.setSize(8, 8, 8);
			buildingSprite.sprites = [isoImage];
			addChild(buildingSprite);
            buildingSprite.container.mouseChildren = false;
            
			buildingSprite.container.addEventListener(MouseEvent.CLICK, onMouseClick);
			buildingSprite.container.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			buildingSprite.container.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		protected function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			buildingSprite.container.filters = [new ColorMatrixFilter(BFont.brightFilter)];
		}

		protected function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			buildingSprite.container.filters = null;
		}

		protected function onMouseClick(event:MouseEvent):void
		{
		}

		public function destroy():void
		{
		} 
	}
}